package person.learn.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ApplicationObjectSupport;

/**
 * Created by barton on 16-1-25.
 *
 * 1.@Configuration tags the class as a source of bean definitions for the application context
 * 2.使用@Configuration注解将ApplicationContextUtil注入到spring容器中才能获得ApplicationContext的实例
 */
@Configuration
public class ApplicationContextUtil extends ApplicationObjectSupport {

    public Object getBean(String name) throws BeansException {
        return getApplicationContext().getBean(name);
    }

    public <T> T getBean(String name, Class<T> requiredType) throws BeansException {
        return getApplicationContext().getBean(name, requiredType);
    }
}
